<?php

//ini_set('display_errors', 'On');
//error_reporting(E_ALL);

/**
 *功能：定期（天）从账单库的DMZConsumePerRoleDay消费表里面获取被推广人的消费信息
 *      更新推广员的积分和返还51点。
 */
require_once(CORE_ROOT . '/public/library/common/network/fiveonelib_sock_stream.php');
require_once(CORE_ROOT . '/public/library/game/common_define.php');
require_once(CORE_ROOT . '/public/library/dmz/gm_protocol.php');
//GM Server

/**
 * GM Server
 */
class gm_server{
    protected $socket_stream;

    public function __construct(){
        $this->socket_stream = new Fiveonelib_SockStream(AF_INET, SOL_TCP);
        $config              = array(
            'host' => '10.11.13.181', //线上10.10.12.153
            'port' => '8014'
        );
        $this->socket_stream->connect($config['host'], $config['port'], 3);
    }

    /**
     * 获取游戏玩家信息
     * @return object
     */
    function getUserGameInfo($roleId, $roleType, $nickName, $clientId, $regionId){

        $roleInfoRequest             = new CRequestGMGetRoleInfo();
        $roleInfoRequest->roleType   = $roleType;
        $roleInfoRequest->szRoleName = $nickName;
        $roleInfoRequest->roleID     = $roleId;
        $roleInfoRequest->nClientID  = $clientId;
        $roleInfoRequest->nRegion    = $regionId;

        $roleInfoRequest->encode($body, $bodyLength);

        $cshead                  = new CCSHead();
        $cshead->shPackageLength = $bodyLength + $cshead->size();
        $cshead->nHeaderLen      = $cshead->size();
        $cshead->shMessageID     = MSGID_CGM_REQ_GETROLEINFO;
        $cshead->shMessageType   = 0x0001;
        $cshead->nUIN            = $roleId;
        $cshead->encode($head, $headLength);

        $send_result = $this->socket_stream->write($head . $body, $headLength + $bodyLength + 1, 5, 5);

        //echo '$head:' . bin2hex($head) . "<br>\n";
        //echo '$body:' . bin2hex($body) . "<br>\n";
        //echo 'send_result:' . $send_result . "<br>\n";
        if(0 == $send_result){
            return FALSE;
        }
        //echo '$roleId=' . $roleId;
        $recieve_result = $this->socket_stream->read(4, 5, 5);
        //echo 'packageLength:' . bin2hex($recieve_result) . "<br>\n";
        if($recieve_result != NULL){
            CCodeEngine::decode_int32(&$recieve_result, $packageLegth);
            $recieve_result = $this->socket_stream->read($packageLegth - 4, 5, 5);
            //echo '$recieve_result:' . bin2hex($recieve_result) . "<br>\n";
            if($recieve_result !== FALSE){
                //echo 'result:'. bin2hex(substr($recieve_result, 24)) . "<br>\n";
                $get_role_info_response = new CResponseGMGetRoleInfo();
                $get_role_info_response->decode(substr($recieve_result, 24), $packageLegth - 28);
                return $get_role_info_response;
            }
        }
        return FALSE;
    }

    /**
     * 发送51点
     *
     * @param $roleId
     * @param $clientId
     * @param $nRegion
     * @param $szOperatorName
     * @param $updateMeans
     * @param $assetType
     * @param $arrAsset
     * @param $note
     *
     * @return object
     */
    public function send51Point($roleId, $clientId, $nRegion, $szOperatorName, $updateMeans, $assetType, $arrAsset, $email = array(), $note = '', $nFrom = 111, $nChannelID){
        $req                 = new CRequestUpdateAsset();
        $req->roleID         = $roleId;
        $req->nClientID      = $clientId;
        $req->nRegion        = $nRegion;
        $req->szOperatorName = $szOperatorName;
        $req->updateMeans    = $updateMeans;
        $req->assetType      = $assetType;
        $req->arrAsset       = $arrAsset;
        $req->szDescription  = $note;

        $req->sendMail      = $email['is_mail'];
        $req->szSenderName  = $email['sender'];
        $req->szMailContent = $email['content'];
        $req->nFrom         = $nFrom;
        $req->nChannelID    = $nChannelID;
        //echo '<pre>';
        //print_r($req);

        $req->encode($body, $bodyLength);

        $cshead                  = new CCSHead();
        $cshead->shPackageLength = $bodyLength + $cshead->size();
        $cshead->nHeaderLen      = $cshead->size();
        $cshead->shMessageID     = MSGID_CGM_REQ_UPDATEASSET;
        $cshead->shMessageType   = 0x0001;
        $cshead->nUIN            = $roleId;
        $cshead->encode($head, $headLength);

        $send_result = $this->socket_stream->write($head . $body, $headLength + $bodyLength + 1, 3, 5);

        //echo '$head:' . bin2hex($head) . "<br>\n";
        //echo '$body:' . bin2hex($body) . "<br>\n";
        //echo 'send_result:' . $send_result . "<br>\n";
        if(0 == $send_result){
            return FALSE;
        }

        $recieve_result = $this->socket_stream->read(4, 5, 5);
        //echo 'packageLength:' . bin2hex($recieve_result) . "<br>\n";
        if($recieve_result != NULL){
            CCodeEngine::decode_int32(&$recieve_result, $packageLegth);
            $recieve_result = $this->socket_stream->read($packageLegth - 4, 5, 5);
            //echo '$recieve_result:' . bin2hex($recieve_result) . "<br>\n";
            if($recieve_result !== FALSE){
                //echo 'result:'. bin2hex(substr($recieve_result, 24)) . "<br>\n";
                $gm_response = new CResponseUpdateAsset();
                $gm_response->decode(substr($recieve_result, 24), $packageLegth - 28);

                return $gm_response;
            }
        }

        return FALSE;
    }

    /****/
    function sendGoods($roleId, $clientId, $region, $szOperatorName, $arrItemUnit, $note = '', $op = 1){
        if($op == 1){
            $gm_update_item_request = new GMRequestAddItem();
        }else{
            $gm_update_item_request = new GMRequestDelItem();
        }

        $gm_update_item_request->roleID         = $roleId;
        $gm_update_item_request->nClientID      = $clientId;
        $gm_update_item_request->nRegion        = $region;
        $gm_update_item_request->szOperatorName = $szOperatorName;
        $gm_update_item_request->nFrom          = 1;
        $gm_update_item_request->nItemUnitCount = count($arrItemUnit);
        $gm_update_item_request->arrItemUnit    = $arrItemUnit;
        if($op == 1){
            $gm_update_item_request->szDescription = $note;
        }

        //var_dump($gm_update_item_request);

        $gm_update_item_request->encode($body, $bodyLength);

        $cshead                  = new CCSHead();
        $cshead->shPackageLength = $bodyLength + $cshead->size();
        $cshead->nHeaderLen      = $cshead->size();
        $cshead->shMessageID     = $op == 1 ? MSGID_CGM_REQ_ADDITEM : MSGID_CGM_REQ_DELETEITEM; //添加：删除
        $cshead->shMessageType   = 0x0001;
        $cshead->nUIN            = $roleId;
        $cshead->encode($head, $headLength);

        $send_result = $this->socket_stream->write($head . $body, $headLength + $bodyLength + 1, 1, 5);

        //echo '$head:' . bin2hex($head) . "<br>\n";
        //echo '$body:' . bin2hex($body) . "<br>\n";
        //echo 'send_result:' . $send_result . "<br>\n";
        if(0 == $send_result){
            return FALSE;
        }

        $recieve_result = $this->socket_stream->read(4, 1, 5);
        //echo 'packageLength:' . bin2hex($recieve_result) . "<br>\n";
        if($recieve_result != NULL){
            CCodeEngine::decode_int32(&$recieve_result, $packageLegth);
            $recieve_result = $this->socket_stream->read($packageLegth - 4, 1, 5);
            //echo '$recieve_result:' . bin2hex($recieve_result) . "<br>\n";
            if($recieve_result !== FALSE){
                //echo 'result:'. bin2hex(substr($recieve_result, 24)) . "<br>\n";
                $gm_response = new CResponseAddItem();
                $gm_response->decode(substr($recieve_result, 24), $packageLegth - 28);

                return $gm_response;
            }
        }
        return FALSE;
    }

    /**
     * 发送邮件
     */
    function sendMail($roleID, $nClientID, $nRegion, $stMailUnit){
        $gm_sendmail_request             = new GMRequestSendMail();
        $gm_sendmail_request->roleID     = $roleID;
        $gm_sendmail_request->nClientID  = $nClientID;
        $gm_sendmail_request->nRegion    = $nRegion;
        $gm_sendmail_request->stMailUnit = $stMailUnit;

        //var_dump($gm_sendmail_request);
        //echo 'encode start';
        $gm_sendmail_request->encode($body, $bodyLength);
        //echo 'encode end';
        $cshead                  = new CCSHead();
        $cshead->shPackageLength = $bodyLength + $cshead->size();
        $cshead->nHeaderLen      = $cshead->size();
        $cshead->shMessageID     = 0x0B09;
        $cshead->shMessageType   = 0x0001;
        $cshead->nUIN            = $roleID;
        $cshead->encode($head, $headLength);

        $send_result = $this->socket_stream->write($head . $body, $headLength + $bodyLength + 1, 1, 5);

        //echo '$head:' . bin2hex($head) . "<br>\n";
        //echo '$body:' . bin2hex($body) . "<br>\n";
        //echo 'send_result:' . $send_result . "<br>\n";
        if(0 == $send_result){
            return FALSE;
        }

        $recieve_result = $this->socket_stream->read(4, 3, 5);
        //echo 'packageLength:' . bin2hex($recieve_result) . "<br>\n";
        if($recieve_result != NULL){
            CCodeEngine::decode_int32(&$recieve_result, $packageLegth);
            $recieve_result = $this->socket_stream->read($packageLegth - 4, 1, 5);
            //echo '$recieve_result:' . bin2hex($recieve_result) . "<br>\n";
            if($recieve_result !== FALSE){
                //echo 'result:'. bin2hex(substr($recieve_result, 24)) . "<br>\n";
                $gm_sendmail_response = new CResponseSendMail();
                $gm_sendmail_response->decode(substr($recieve_result, 24), $packageLegth - 28);

                return $gm_sendmail_response;
            }
        }

        return FALSE;
    }

    /*
    *邮件发送道具
    */
    public function sendMailPacket($session_id, $nRegion, $mail_id, $occurrence_time, $deadline, $dest_id, $source_id, $source_name, $operatorName, $szDescription, $prizeNoti, $itemCount, $itemUnit, $nFrom){
        $gm_sendMailPacket_request                   = new GMRequestMailPacketAdd();
        $gm_sendMailPacket_request->session_id_      = $session_id;
        $gm_sendMailPacket_request->nRegion          = $nRegion;
        $gm_sendMailPacket_request->mail_id_         = $mail_id;
        $gm_sendMailPacket_request->occurrence_time_ = $occurrence_time;
        $gm_sendMailPacket_request->deadline_        = $deadline;
        $gm_sendMailPacket_request->dest_id_         = $dest_id;
        $gm_sendMailPacket_request->source_id_       = $source_id;
        $gm_sendMailPacket_request->source_name_     = $source_name;
        $gm_sendMailPacket_request->operatorName     = $operatorName;
        $gm_sendMailPacket_request->szDescription    = $szDescription;
        $gm_sendMailPacket_request->prizeNoti        = $prizeNoti;
        $gm_sendMailPacket_request->itemCount        = $itemCount;
        $gm_sendMailPacket_request->itemUnit         = $itemUnit;
        $gm_sendMailPacket_request->nFrom            = $nFrom;

        //var_dump($gm_sendMailPacket_request);
        //echo 'encode start <br>';
        $gm_sendMailPacket_request->encode($body, $bodyLength);
        //echo 'encode end <br>';
        $cshead                  = new CCSHead();
        $cshead->shPackageLength = $bodyLength + $cshead->size();
        $cshead->nHeaderLen      = $cshead->size();
        $cshead->shMessageID     = 0x0B0A;
        $cshead->shMessageType   = 0x0001;
        $cshead->nUIN            = $dest_id;
        $cshead->encode($head, $headLength);

        $send_result = $this->socket_stream->write($head . $body, $headLength + $bodyLength + 1, 1, 5);

        //echo '$head:' . bin2hex($head) . "<br>\n";
        //echo '$body:' . bin2hex($body) . "<br>\n";
        //echo 'send_result:' . $send_result . "<br>\n";
        if(0 == $send_result){
            return FALSE;
        }

        $recieve_result = $this->socket_stream->read(4, 3, 5);
        //echo 'packageLength:' . bin2hex($recieve_result) . "<br>\n";
        if($recieve_result != NULL){
            CCodeEngine::decode_int32(&$recieve_result, $packageLegth);
            $recieve_result = $this->socket_stream->read($packageLegth - 4, 1, 5);
            //echo '$recieve_result:' . bin2hex($recieve_result) . "<br>\n";
            if($recieve_result !== FALSE){
                // echo 'result:'. bin2hex(substr($recieve_result, 24)) . "<br>\n";
                $gm_sendMailPacket_response = new CResponseMailPacketAdd();
                $gm_sendMailPacket_response->decode(substr($recieve_result, 24), $packageLegth - 28);

                return $gm_sendMailPacket_response;
            }
        }

        return FALSE;
    }

    /**
     * 返点日志
     *
     * @param $account
     * @param $zone_id
     * @param $score
     * @param $status
     *
     * @return bool
     */
    public function log($account, $zone_id, $score, $status){
        $cur_time = date('Y-m-d H:i:s', time());
        $result   = mysql_query("insert into feedback_log (`account`, `zone_id`, `point`, `log_time`, `status`) values('$account', $zone_id, $score, '$cur_time', $status)", $this->dbconn);

        return $result;
    }

    //获取家族信息 by zhoug 2011-6-6
    function getFamilyGeneralInfo($roleId, $clientId, $region, $keyType, $keyValue){
        $gm_get_family_general_info_request = new CRequestGMGetFamilyGeneralInfo();

        $gm_get_family_general_info_request->nRoleID   = $roleId;
        $gm_get_family_general_info_request->keyType   = $keyType;
        $gm_get_family_general_info_request->keyValue  = $keyValue;
        $gm_get_family_general_info_request->nClientID = $clientId;
        $gm_get_family_general_info_request->nRegion   = $region;
        $gm_get_family_general_info_request->nFrom     = 1;

        //      	var_dump($gm_get_family_general_info_request);

        $gm_get_family_general_info_request->encode($body, $bodyLength);

        $cshead                  = new CCSHead();
        $cshead->shPackageLength = $bodyLength + $cshead->size();
        $cshead->nHeaderLen      = $cshead->size();
        $cshead->shMessageID     = MSGID_CGM_REQ_GETFAMILYGENERALINFO;
        $cshead->shMessageType   = 0x0001;
        $cshead->nUIN            = 123456;
        $cshead->encode($head, $headLength);

        $send_result = $this->socket_stream->write($head . $body, $headLength + $bodyLength + 1, 1, true);

        //        echo '$head:' . bin2hex($head) . "<br>\n";
        //        echo '$body:' . bin2hex($body) . "<br>\n";
        //        echo 'send_result:' . $send_result . "<br>\n";

        if(0 == $send_result){
            return FALSE;
        }

        $recieve_result = $this->socket_stream->read(4, 6, true);
        //        echo 'packageLength:' . bin2hex($recieve_result) . "<br>\n";
        if($recieve_result != NULL){
            CCodeEngine::decode_int32(&$recieve_result, $packageLegth);
            $recieve_result = $this->socket_stream->read($packageLegth - 4, 6, true);
            //            echo '$recieve_result:' . bin2hex($recieve_result) . "<br>\n";
            if($recieve_result !== FALSE){
                //                echo 'result:'. bin2hex(substr($recieve_result, 24)) . "<br>\n";
                $gm_response = new CResponseGMGetFamilyGeneralInfo();
                $gm_response->decode(substr($recieve_result, 24), $packageLegth - 28);

                return $gm_response;
            }
        }

        return FALSE;
    }

    //批量查询角色昵称
    function getAllRoleInfo($nCount, $arrRoleID, $nClientID, $nRegion){
        $roleInfoRequest            = new CRequestGMGetRoleGeneralInfo();
        $roleInfoRequest->nCount    = $nCount;
        $roleInfoRequest->arrRoleID = $arrRoleID;
        $roleInfoRequest->nClientID = $nClientID;
        $roleInfoRequest->nRegion   = $nRegion;

        $roleInfoRequest->encode($body, $bodyLength);

        $cshead                  = new CCSHead();
        $cshead->shPackageLength = $bodyLength + $cshead->size();
        $cshead->nHeaderLen      = $cshead->size();
        $cshead->shMessageID     = MSGID_CGM_REQ_GETROLEGENERALINFO;
        $cshead->shMessageType   = 0x0001;
        $cshead->nUIN            = 123456;
        $cshead->encode($head, $headLength);

        $send_result = $this->socket_stream->write($head . $body, $headLength + $bodyLength + 1, 5, 5);

        // echo '$head:' . bin2hex($head) . "<br>\n";
        // echo '$body:' . bin2hex($body) . "<br>\n";
        // echo 'send_result:' . $send_result . "<br>\n";

        if(0 == $send_result){
            return FALSE;
        }
        $recieve_result = $this->socket_stream->read(4, 5, 5);
        // echo 'packageLength:' . bin2hex($recieve_result) . "<br>\n";
        if($recieve_result != NULL){
            CCodeEngine::decode_int32(&$recieve_result, $packageLength);
            $recieve_result = $this->socket_stream->read($packageLength - 4, 5, 5);
            // echo '$recieve_result:' . bin2hex($recieve_result) . "<br>\n";
            if($recieve_result !== FALSE){
                // echo 'result:'. bin2hex(substr($recieve_result, 24)) . "<br>\n";
                $get_role_info_response = new CResponseGMGetRoleGeneralInfo();
                $get_role_info_response->decode(substr($recieve_result, 24), $packageLength - 28);
                return $get_role_info_response;
            }
        }
        return FALSE;
    }

    //获取情侣信息 by chengmiao 2012-2-10 16:03:09
    function getLoverInfo($roleId, $clientId, $regionId){
        $request            = new CRequestGMGetLoverInfo();
        $request->nRoleID   = $roleId;
        $request->nClientID = $clientId;
        $request->nRegion   = $regionId;
        $request->encode($body, $bodyLength);

        $cshead                  = new CCSHead();
        $cshead->shPackageLength = $bodyLength + $cshead->size();
        $cshead->nHeaderLen      = $cshead->size();
        $cshead->shMessageID     = MSGID_CGM_REQ_GETLOVERINFO;
        $cshead->shMessageType   = 0x0001;
        $cshead->nUIN            = $roleId;
        $cshead->encode($head, $headLength);

        $send_result = $this->socket_stream->write($head . $body, $headLength + $bodyLength + 1, 5, true);

        if(0 == $send_result){
            return FALSE;
        }
        $recieve_result = $this->socket_stream->read(4, 5, true);
        if($recieve_result != NULL){
            CCodeEngine::decode_int32(&$recieve_result, $packageLength);
            $recieve_result = $this->socket_stream->read($packageLength - 4, 1, true);
            if($recieve_result !== FALSE){
                $response = new CResponseGMGetLoverInfo();
                $response->decode(substr($recieve_result, 24), $packageLength - 28);
                return $response;
            }
        }

        return FALSE;
    }

    /**
     * 用户惩罚，冻结51点，解冻51点点
     *
     * @param $roleId
     * @param $clientId
     * @param $punishLevel
     * @param $nPunishEndTime
     * @param $szPunishReason
     * @param $nRegion
     */
    function punish($roleId, $clientId, $punishLevel, $nPunishEndTime, $szPunishReason, $nRegion){
        $punishRequest = new CRequestGMUpdatePunish();

        $punishRequest->operaRoleID    = 1;
        $punishRequest->roleID         = $roleId;
        $punishRequest->nClientID      = $clientId;
        $punishRequest->punishLevel    = $punishLevel;
        $punishRequest->nPunishEndTime = $nPunishEndTime;
        $punishRequest->nRegion        = $nRegion;
        $punishRequest->szPunishReason = $szPunishReason;
        $punishRequest->nFrom          = 1;

        $punishRequest->encode($body, $bodyLength);

        $cshead                  = new CCSHead();
        $cshead->shPackageLength = $bodyLength + $cshead->size();
        $cshead->nHeaderLen      = $cshead->size();
        $cshead->shMessageID     = MSGID_CGM_REQ_UPDATEPUNISH;
        $cshead->shMessageType   = 0x0001;
        $cshead->nUIN            = $roleId;
        $cshead->encode($head, $headLength);

        $send_result = $this->socket_stream->write($head . $body, $headLength + $bodyLength + 1, 1, true);

        if(0 == $send_result){
            return FALSE;
        }

        $recieve_result = $this->socket_stream->read(4, 1, true);
        if($recieve_result != NULL){
            CCodeEngine::decode_int32(&$recieve_result, $packageLegth);
            $recieve_result = $this->socket_stream->read($packageLegth - 4, 1, true);
            if($recieve_result !== FALSE){
                $punish_response = new CResponseGMUpdatePunish();
                $punish_response->decode(substr($recieve_result, 24), $packageLegth - 28);
                return $punish_response;
            }
        }

        return FALSE;
    }

    /**
     * 获取游戏玩家好友列表
     * @return object
     */
    function getFriendList($roleId, $clientId, $regionId){

        $roleInfoRequest            = new GMGetFriendListReq();
        $roleInfoRequest->roleID    = $roleId;
        $roleInfoRequest->nClientID = $clientId;
        $roleInfoRequest->nRegion   = $regionId;

        $roleInfoRequest->encode($body, $bodyLength);

        $cshead                  = new CCSHead();
        $cshead->shPackageLength = $bodyLength + $cshead->size();
        $cshead->nHeaderLen      = $cshead->size();
        $cshead->shMessageID     = MSGID_GMC_REQ_GETFRIENDLIST;
        $cshead->shMessageType   = 0x0001;
        $cshead->nUIN            = $roleId;
        $cshead->encode($head, $headLength);

        $send_result = $this->socket_stream->write($head . $body, $headLength + $bodyLength + 1, 5, 5);

        //echo '$head:' . bin2hex($head) . "<br>\n";
        //echo '$body:' . bin2hex($body) . "<br>\n";
        //echo 'send_result:' . $send_result . "<br>\n";
        if(0 == $send_result){
            return FALSE;
        }
        //echo '$roleId=' . $roleId;
        $recieve_result = $this->socket_stream->read(4, 5, 5);
        //echo 'packageLength:' . bin2hex($recieve_result) . "<br>\n";
        if($recieve_result != NULL){
            CCodeEngine::decode_int32(&$recieve_result, $packageLegth);
            $recieve_result = $this->socket_stream->read($packageLegth - 4, 5, 5);
            //echo '$recieve_result:' . bin2hex($recieve_result) . "<br>\n";
            if($recieve_result !== FALSE){
                //echo 'result:'. bin2hex(substr($recieve_result, 24)) . "<br>\n";
                $get_role_info_response = new GMGetFriendListResp();
                $get_role_info_response->decode(substr($recieve_result, 24), $packageLegth - 28);
                return $get_role_info_response;
            }
        }
        return FALSE;
    }

    //获取玩家物品信息   by shiting 2012-8-1
    function viewItemList($roleId, $clientId, $regionId){
        $itemListRequest            = new CRequestGMGetItemList();
        $itemListRequest->roleID    = $roleId;
        $itemListRequest->nClientID = $clientId;
        $itemListRequest->nRegion   = $regionId;
        $itemListRequest->encode($body, $bodyLength);
        $cshead                  = new CCSHead();
        $cshead->shPackageLength = $bodyLength + $cshead->size();
        $cshead->nHeaderLen      = $cshead->size();
        $cshead->shMessageID     = MSGID_CGM_REQ_GETITEMLIST;
        $cshead->shMessageType   = 0x0001;
        $cshead->nUIN            = $roleId;
        $cshead->encode($head, $headLength);
        $send_result = $this->socket_stream->write($head . $body, $headLength + $bodyLength + 1, 1, 5);
        if(0 == $send_result){
            return FALSE;
        }
        $recieve_result = $this->socket_stream->read(4, 1, 5);
        if($recieve_result != NULL){
            CCodeEngine::decode_int32(&$recieve_result, $packageLegth);
            $recieve_result = $this->socket_stream->read($packageLegth - 4, 1, 5);
            if($recieve_result !== FALSE){
                $get_item_list_response = new CResponseGMGetItemList();
                $get_item_list_response->decode(substr($recieve_result, 24), $packageLegth - 28);
                $this->processResponse($get_item_list_response);
                return $get_item_list_response;
            }
        }
        return FALSE;
    }

    function processResponse(&$response){
        if($response->stRoleItemInfo->nItemUnitCount > 0){
            foreach($response->stRoleItemInfo->arrItemUnit as &$_item){
                $_item->nQuantity = $_item->useMeans == 1 ? date("Y-m-d h:i:s", $_item->nQuantity) : $_item->nQuantity;
                //$_item->useMeans = isset($this->useMeans[$_item->useMeans]) ? $this->useMeans[$_item->useMeans] : $this->useMeans[0];
                $_item->nTimeLimit = date("Y-m-d h:i:s", $_item->nTimeLimit);
            }
        }
    }

    //批量得VIP信息
    function getAllVipInfo($nRoleID, $nCount, $arrRoleID, $nClientID, $nRegion){
        $roleInfoRequest            = new GMGetVipInfoReq();
        $roleInfoRequest->nRoleID   = $nRoleID;
        $roleInfoRequest->nClientID = $nClientID;
        $roleInfoRequest->nRegion   = $nRegion;
        $roleInfoRequest->nVipCount = $nCount;
        $roleInfoRequest->arrRoleID = $arrRoleID;

        $roleInfoRequest->encode($body, $bodyLength);

        $cshead                  = new CCSHead();
        $cshead->shPackageLength = $bodyLength + $cshead->size();
        $cshead->nHeaderLen      = $cshead->size();
        $cshead->shMessageID     = MSGID_GMC_REQ_GETVIPINFO;
        $cshead->shMessageType   = 0x0001;
        $cshead->nUIN            = 123456;
        $cshead->encode($head, $headLength);

        $send_result = $this->socket_stream->write($head . $body, $headLength + $bodyLength + 1, 5, 5);

        // echo '$head:' . bin2hex($head) . "<br>\n";
        // echo '$body:' . bin2hex($body) . "<br>\n";
        // echo 'send_result:' . $send_result . "<br>\n";

        if(0 == $send_result){
            return FALSE;
        }
        $recieve_result = $this->socket_stream->read(4, 5, 5);
        // echo 'packageLength:' . bin2hex($recieve_result) . "<br>\n";
        if($recieve_result != NULL){
            CCodeEngine::decode_int32(&$recieve_result, $packageLength);
            $recieve_result = $this->socket_stream->read($packageLength - 4, 5, 5);
            // echo '$recieve_result:' . bin2hex($recieve_result) . "<br>\n";
            if($recieve_result !== FALSE){
                // echo 'result:'. bin2hex(substr($recieve_result, 24)) . "<br>\n";
                $get_role_info_response = new GMGetVipInfoResp();
                $get_role_info_response->decode(substr($recieve_result, 24), $packageLength - 28);
                return $get_role_info_response;
            }
        }
        return FALSE;
    }

}

;

?>
